package com.ql.service.bedService;

import com.ql.dao.bed.BedMapper;
import com.ql.pojo.bed.Bed;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service("bedService")
public class BedServiceImpl implements BedService {
    private static final Logger LOGGER = Logger.getLogger( BedServiceImpl.class );
    @Resource
    private BedMapper bedMapper;

    @Override
    public List<Bed> qryByKid(int kNo) {
        List<Bed> bedList = null;
        try {
            bedList = bedMapper.qryByKid( kNo );
        } catch (Exception e) {
            LOGGER.error( "BedServiceImpl.qryByKid异常" + e.getMessage() );
        }
        return bedList;
    }

    //查找所有床位列表
    @Override
    public List<Bed> qryAllBed(PageHelper ph, String qryKName, int qrybNo, int qryStatent) {
        List<Bed> bedList = null;
        try {
            ph.setTotalCount( bedMapper.count( qryKName, qrybNo, qryStatent ) );
            bedList = bedMapper.qryAllBed( (ph.getCurrentPageNo() - 1) * ph.getPageSize(), ph.getPageSize(), qryKName, qrybNo, qryStatent );
        } catch (Exception e) {
            LOGGER.error( "BedServiceImpl.qryAllBed异常" + e.getMessage() );
        }
        return bedList;
    }

    //由床位Id查找床位信息
    @Override
    public Bed qryByID(int bNo) {
        Bed bed = null;
        try {
            bed = bedMapper.qryById( bNo );
        } catch (Exception e) {
            LOGGER.error( "BedServiceImpl.qryByID异常" + e.getMessage() );
        }
        return bed;
    }
    //由床位Id查找所有床位信息
    @Override
    public Bed qryAllInfoByID(int bNo) {
        Bed bed = null;
        try {
            bed = bedMapper.qryAllInfoById( bNo );
        } catch (Exception e) {
            LOGGER.error( "BedServiceImpl.qryAllInfoByID异常" + e.getMessage() );
        }
        return bed;
    }

    //更新床位信息
    @Override
    public boolean updBed(Bed bed) {
        int row = 0;
        try {
            row = bedMapper.updBedById( bed );
            if (row == 1) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            LOGGER.error( "BedServiceImpl.updBed异常" + e.getMessage() );
            return false;
        }
    }

//    新增床位
    @Override
    public boolean addBed(Bed bed) {
        int row = 0;
        try {
            row = bedMapper.saveBed( bed );
        if (row==1){
            return true;
        }else {
            return false;
        }
        } catch (Exception e) {
            LOGGER.error( "新增床位异常" );
            return false;
        }
    }
//删除床位
    @Override
    public boolean delBed(int bNo) {
        int row= 0;
        try {
            row = bedMapper.delBed( bNo );
            if (row==1){
                return true;
            }else {
                return false;
            }
        } catch (Exception e) {
            LOGGER.error( "删除床位异常" );
        return false;
        }
    }
}
